home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form frmMainForm
- BorderStyle = 1 'Fixed Single
- Caption = "VB/ISAM Sample Program SAM4 -- browse/edit ""VB Companion Products"" database"
- ClientHeight = 6825
- ClientLeft = 300
- ClientTop = 345
- ClientWidth = 9270
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 12
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 7230
- Icon = SAM4MAIN.FRX:0000
- Left = 240
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 6825
- ScaleWidth = 9270
- Top = 0
- Width = 9390
- Begin CommonDialog cdbExport
- CancelError = -1 'True
- Filter = "Comma-separated values|*.CSV"
- FilterIndex = 1
- Left = 4380
- Top = 3180
- End
- Begin Timer tmrTimer1
- Enabled = 0 'False
- Interval = 150
- Left = 4050
- Top = 3180
- End
- Begin CommonDialog cdbOpenADataset
- CancelError = -1 'True
- Filter = "VB/ISAM dataset|*.ISM"
- FilterIndex = 1
- Left = 4380
- Top = 3090
- End
- Begin SSPanel pnlMainDisplay
- Align = 2 'Align Bottom
- Alignment = 0 'Left Justify - TOP
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 2 'Raised w/heavy shading
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 12
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- ForeColor = &H00FF0000&
- Height = 5745
- Left = 0
- TabIndex = 18
- Top = 1080
- Width = 9270
- Begin SSPanel pnlDatasetName
- Alignment = 1 'Left Justify - MIDDLE
- BackColor = &H00C0C0C0&
- BevelOuter = 0 'None
- Caption = "Dataset name: [click Open]"
- Font3D = 2 'Raised w/heavy shading
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 12
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- ForeColor = &H00FF0000&
- Height = 375
- Left = 210
- TabIndex = 21
- Top = 90
- Width = 8955
- End
- Begin SSPanel pnlUpdateButtons
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 2 'Raised w/heavy shading
- ForeColor = &H00FF0000&
- Height = 3705
- Left = 7110
- TabIndex = 25
- Top = 1800
- Width = 1935
- Begin SSCommand cmdClearDisplay
- Caption = "Clear/Restore Display"
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 870
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:0302
- TabIndex = 13
- Top = 90
- Width = 1755
- End
- Begin SSCommand cmdUpdateRec
- Caption = "Update This Record"
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:0604
- TabIndex = 16
- Top = 2730
- Width = 1755
- End
- Begin SSCommand cmdDeleteRec
- Caption = "Delete This Record"
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:0906
- TabIndex = 15
- Top = 1845
- Width = 1755
- End
- Begin SSCommand cmdAddRec
- Caption = "Add This Record"
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:0C08
- TabIndex = 14
- Top = 960
- Width = 1755
- End
- End
- Begin SSPanel pnlCombo
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 2 'Raised w/heavy shading
- ForeColor = &H00FF0000&
- Height = 495
- Left = 7110
- TabIndex = 24
- Top = 900
- Width = 1935
- Begin ComboBox cboIndex
- BackColor = &H00FFFF00&
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 300
- Left = 90
- Sorted = -1 'True
- Style = 2 'Dropdown List
- TabIndex = 12
- Top = 90
- Width = 1755
- End
- End
- Begin SSPanel pnlIndexName
- BackColor = &H00C0C0C0&
- BevelOuter = 0 'None
- Caption = "Index field:"
- Font3D = 2 'Raised w/heavy shading
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 12
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- ForeColor = &H00FF0000&
- Height = 375
- Left = 7110
- TabIndex = 23
- Top = 480
- Width = 1425
- End
- Begin SSPanel pnlList
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 0 'None
- Height = 3705
- Left = 240
- TabIndex = 20
- Top = 1800
- Width = 6735
- Begin PictureBox picFieldDisplayArea
- BackColor = &H00C0C0C0&
- BorderStyle = 0 'None
- Height = 3525
- Left = 90
- ScaleHeight = 3525
- ScaleWidth = 6555
- TabIndex = 27
- TabStop = 0 'False
- Top = 90
- Visible = 0 'False
- Width = 6555
- Begin TextBox txtFieldVal
- Height = 285
- Index = 10
- Left = 2130
- TabIndex = 26
- Top = 3180
- Width = 4275
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 9
- Left = 2130
- TabIndex = 48
- Top = 2865
- Width = 1695
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 8
- Left = 2130
- TabIndex = 47
- Top = 2550
- Width = 1695
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 7
- Left = 2130
- MaxLength = 35
- TabIndex = 46
- Top = 2235
- Width = 4275
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 6
- Left = 2130
- MaxLength = 3
- TabIndex = 45
- Top = 1920
- Width = 495
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 5
- Left = 2130
- TabIndex = 44
- Top = 1605
- Width = 4275
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 4
- Left = 2130
- TabIndex = 43
- Top = 1290
- Width = 1755
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 3
- Left = 2130
- MaxLength = 3
- TabIndex = 42
- Top = 975
- Width = 495
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 2
- Left = 2130
- MaxLength = 45
- TabIndex = 41
- Top = 660
- Width = 4275
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 1
- Left = 2130
- TabIndex = 40
- Top = 345
- Width = 4275
- End
- Begin TextBox txtFieldVal
- Height = 285
- Index = 0
- Left = 2130
- MaxLength = 50
- TabIndex = 28
- Top = 30
- Width = 4275
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 10
- Left = 90
- TabIndex = 39
- Top = 3180
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 9
- Left = 90
- TabIndex = 38
- Top = 2865
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 8
- Left = 90
- TabIndex = 37
- Top = 2550
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 7
- Left = 90
- TabIndex = 36
- Top = 2235
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 6
- Left = 90
- TabIndex = 35
- Top = 1920
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 5
- Left = 90
- TabIndex = 34
- Top = 1605
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 4
- Left = 90
- TabIndex = 33
- Top = 1290
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 3
- Left = 90
- TabIndex = 32
- Top = 975
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 2
- Left = 90
- TabIndex = 31
- Top = 660
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 1
- Left = 90
- TabIndex = 30
- Top = 345
- Width = 1965
- End
- Begin Label lblFieldName
- BackStyle = 0 'Transparent
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Index = 0
- Left = 90
- TabIndex = 29
- Top = 60
- Width = 1965
- End
- End
- End
- Begin SSPanel pnlVCRButtons
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 0 'None
- Height = 1125
- Left = 240
- TabIndex = 19
- Top = 510
- Width = 6735
- Begin SSPanel pnlFindText
- Alignment = 6 'Center - TOP
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 2 'Raised w/heavy shading
- ForeColor = &H00FF0000&
- Height = 945
- Left = 2130
- TabIndex = 22
- Top = 90
- Width = 2475
- Begin SSCommand cmdVCRSeek
- Enabled = 0 'False
- Font3D = 0 'None
- Height = 495
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:0F0A
- TabIndex = 9
- Top = 360
- Width = 2295
- End
- Begin TextBox txtFind
- Enabled = 0 'False
- Height = 285
- Left = 90
- TabIndex = 8
- Top = 60
- Width = 2295
- End
- End
- Begin SSCommand cmdVCRLast
- Enabled = 0 'False
- Font3D = 0 'None
- Height = 945
- Left = 5640
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:120C
- TabIndex = 11
- Top = 90
- Width = 1005
- End
- Begin SSCommand cmdVCRRight
- Enabled = 0 'False
- Font3D = 0 'None
- Height = 945
- Left = 4620
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:150E
- TabIndex = 10
- Top = 90
- Width = 1020
- End
- Begin SSCommand cmdVCRLeft
- Enabled = 0 'False
- Font3D = 0 'None
- Height = 945
- Left = 1080
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:1810
- TabIndex = 7
- Top = 90
- Width = 1035
- End
- Begin SSCommand cmdVCRFirst
- Enabled = 0 'False
- Font3D = 0 'None
- Height = 945
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:1B12
- TabIndex = 6
- Top = 90
- Width = 990
- End
- End
- Begin Image imgVCRSeek
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:1E14
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgVCRRight
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:2116
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgVCRLeft
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:2418
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgVCRLast
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:271A
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgVCRFirst
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:2A1C
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgUpdateRec
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:2D1E
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDeleteRec
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:3020
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgAddRec
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:3322
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgClearDisplay
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:3624
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgExport
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:3926
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgRenameFields
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:3C28
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgInfo
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:3F2A
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- End
- Begin SSPanel pnlMainButtons
- Align = 1 'Align Top
- BackColor = &H00C0C0C0&
- BevelInner = 1 'Inset
- Font3D = 0 'None
- Height = 1065
- Left = 0
- TabIndex = 17
- Top = 0
- Width = 9270
- Begin SSCommand cmdInfo
- Caption = "Dataset Info..."
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 1590
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:422C
- TabIndex = 1
- Top = 90
- Width = 1530
- End
- Begin SSCommand cmdRenameFields
- Caption = "Rename Fields..."
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 3120
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:452E
- TabIndex = 2
- Top = 90
- Width = 1530
- End
- Begin SSCommand cmdExit
- Caption = "Exit"
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 7710
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:4830
- TabIndex = 5
- Top = 90
- Width = 1470
- End
- Begin SSCommand cmdHelp
- Caption = "Help"
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 6180
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:4B32
- TabIndex = 4
- Top = 90
- Width = 1530
- End
- Begin SSCommand cmdExport
- Caption = "Export to .CSV..."
- Enabled = 0 'False
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 4650
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:4E34
- TabIndex = 3
- Top = 90
- Width = 1530
- End
- Begin SSCommand cmdOpen
- Caption = "Open..."
- Font3D = 0 'None
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 885
- Left = 90
- Outline = 0 'False
- Picture = SAM4MAIN.FRX:5136
- TabIndex = 0
- Top = 90
- Width = 1500
- End
- End
- Begin Image imgDVCRSeek
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:5438
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDVCRRight
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:573A
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDVCRLeft
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:5A3C
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDVCRLast
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:5D3E
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDVCRFirst
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:6040
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDExport
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:6342
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDRenameFields
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:6644
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDInfo
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:6946
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDClearDisplay
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:6C48
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDUpdateRec
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:6F4A
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDDeleteRec
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:724C
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Begin Image imgDAddRec
- Height = 480
- Left = 0
- Picture = SAM4MAIN.FRX:754E
- Top = 0
- Visible = 0 'False
- Width = 480
- End
- Option Explicit
- Sub AssembleRecord ()
- PrimaryKey = DisplayedPrimaryKey
- RecordBuffer.Description = txtFieldVal(1).Text
- RecordBuffer.ProductCategory = txtFieldVal(2).Text
- RecordBuffer.FileType = txtFieldVal(3).Text
- RecordBuffer.BasePrice = Val(US_StripOut((txtFieldVal(4).Text), ",$")) 'The VAL function stops on "$" and "," chars.
- RecordBuffer.PricingNotes = txtFieldVal(5).Text
- RecordBuffer.CatalogPage = Format$(Val(txtFieldVal(6).Text), "000")
- RecordBuffer.CompanyName = txtFieldVal(7).Text
- RecordBuffer.Phone = txtFieldVal(8).Text
- RecordBuffer.Fax = txtFieldVal(9).Text
- RecordBuffer.Comments = txtFieldVal(10).Text
- End Sub
- Sub cboIndex_Click ()
- If cboIndex.ListIndex <> LastIndexListIndex Then 'change
- txtFieldVal(CurrentIndex).BackColor = WHITE
- LastIndexListIndex = cboIndex.ListIndex
- CurrentIndex = Val(Left$(cboIndex.List(cboIndex.ListIndex), 3))
- txtFieldVal(CurrentIndex).BackColor = BLUE
-
- 'Restrict search argument length for this index:
- If CurrentIndex = 0 Then
- txtFind.MaxLength = DatasetInfo.MaxPrimaryKeyLen
- Else
- txtFind.MaxLength = Val(US_LeaveOnly(FieldType(CurrentIndex), "0123456789"))
- End If
- '(re)enable VCR controls in case we were at BOF/EOF in the previously selected index.
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- 'Leave the display alone, but set the index pointer in the new index to this record,
- 'so that the VCR movements will start at this record in the newly-selected index.
- 'To illustrate: Suppose we were dealing with an employee file, browsing though the
- 'employee-name index; if we're looking at Mr. Zugman of the aardvark-processing
- 'department, and switch to the department index, we want to be in the right place.
- 'Remember, each index threads a file of records in a different sequence, and VB/ISAM
- 'maintains separate pointers for each index.
- RefindRecord
- End If
- End Sub
- Sub cmdAddRec_Click ()
- txtFind.Text = ""
- DisplayedPrimaryKey = US_Trim((txtFieldVal(0).Text))
- If DisplayedPrimaryKey = "" Then
- TellUser (NULL_PRIMARY_KEY)
- ElseIf DisplayedPrimaryKey = PrimaryKey Then
- TellUser (CANNOT_READD_SAME_RECORD)
- Else
- AssembleRecord
- rc = VmxPut(DatasetRefNum, PrimaryKey, RecordBuffer, ADD_ONLY)
- If rc = VIS_UPDATE_VIOLATION Then
- TellUser (RECORD_ALREADY_EXISTS)
- ElseIf rc <> VIS_OK Then
- TellUser (PUTERROR)
- ExitProgram 'Panic exit
- Else 'VIS_OK
- FlashDisplay
- ClearOrRestoreToggle = 0
- ChangeAlertFlag = False
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- End If
- End If
- End Sub
- Sub cmdClearDisplay_Click ()
- Dim I As Integer
- If ClearOrRestoreToggle = 0 Then 'Clear display
- SuppressChangeEventFlag = True
- For I = 0 To NumberOfFields
- txtFieldVal(I).Text = ""
- Next I
- SuppressChangeEventFlag = False
- ChangeAlertFlag = False
- ClearOrRestoreToggle = 1
- Else 'Restore original data to display
- DisplayCurrentRecord 'Note, that routine will set toggle to 0
- End If
- End Sub
- Sub cmdDeleteRec_Click ()
- txtFind.Text = ""
- If PrimaryKey <> "" Then
- DisplayedPrimaryKey = US_Trim((txtFieldVal(0).Text))
- If DisplayedPrimaryKey <> PrimaryKey Then
- TellUser (MUST_RESTORE_PRIMARY_KEY)
- Else
- rc = VmxDelete(DatasetRefNum, PrimaryKey)
- If rc <> VIS_OK Then
- TellUser (DELETEERROR)
- ExitProgram
- Else
- ClearOrRestoreToggle = 0
- cmdClearDisplay_Click
- SavedPrimaryKey = PrimaryKey 'needed for RefindRecord procedure
- PrimaryKey = ""
- FlashDisplay
- ChangeAlertFlag = False
- End If
- End If
- End If
- End Sub
- Sub cmdExit_Click ()
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- ExitProgram
- End Sub
- Sub cmdExport_Click ()
- Dim L, T As Integer
- Dim SavePrimaryKey As String
- txtFind.Text = ""
- 'Invoke the common-dialog
- cdbExport.DialogTitle = "Create/select a .CSV file for export"
- cdbExport.Filename = "*.csv"
- 'Set flags for common dialog control:
- ' File must not be read-only
- ' Path must be valid; also,
- ' Hide "read-only" check box
- ' Prompt for overwrite
- cdbExport.Flags = &H8000& Or &H800& Or &H4& Or &H2&
- On Error GoTo DontOpen
- cdbExport.Action = DLG_FILE_SAVE 'Select filename
- ExportFileName = cdbExport.Filename
- If Right$(ExportFileName, 4) <> ".CSV" Then
- TellUser (NOT_A_CSV_FILE)
- Error 32755 'Simulate user pressing "Cancel" button
- End If
- 'We have a filename; open it:
- ExportFileNum = FreeFile
- Open ExportFileName For Binary Access Write As #ExportFileNum
- If LOF(ExportFileNum) > 0 Then
- Close #ExportFileNum
- Kill ExportFileName
- ExportFileNum = FreeFile
- Open ExportFileName For Binary Access Write As #ExportFileNum
- End If
- On Error GoTo 0
- 'Save current position in primary index (to be restored when we return from export)
- rc = VmxGet(DatasetRefNum, 0, XCURRENT + XNO_DATA, "", Throwaway, SavePrimaryKey, Throwaway)
- 'Center frmExport form left/right over frmMainForm, down a bit:
- T = Me.Top + 660
- L = Me.Left + (Me.Width / 2) - (frmExport.Width / 2)
- frmExport.Move L, T
- 'Let the Form_Activate procedure in frmExport take over:
- frmExport!pnlGauge.FloodPercent = 0
- frmExport.Show MODAL
- 'Returned from frmExport; restore position in primary index:
- rc = VmxGet(DatasetRefNum, 0, XLOOKUP + XNO_DATA, SavePrimaryKey, Throwaway, Throwaway, Throwaway)
- 'Done
- Exit Sub
- DontOpen:
- Resume CancelExport
- CancelExport:
- On Error GoTo 0
- Exit Sub
- End Sub
- Sub cmdHelp_Click ()
- Dim L, T As Integer
- txtFind.Text = ""
- 'Center frmHelp form over frmMainForm:
- T = Me.Top + (Me.Height / 2) - (frmHelp.Height / 2)
- L = Me.Left + (Me.Width / 2) - (frmHelp.Width / 2)
- frmHelp.Move L, T
- frmHelp.Show MODAL
- End Sub
- Sub cmdInfo_Click ()
- Dim L, T As Integer
- txtFind.Text = ""
- 'Center frmInfo form over frmMainForm:
- T = Me.Top + (Me.Height / 2) - (frmInfo.Height / 2)
- L = Me.Left + (Me.Width / 2) - (frmInfo.Width / 2)
- frmInfo.Move L, T
- frmInfo.Show MODAL
- End Sub
- Sub cmdOpen_Click ()
- 'This procedure has been hard-wired to open the dataset "c:\vbprod"
- txtFind.Text = ""
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- 'If a dataset is already open, close it and reset the form:
- If DatasetRefNum <> 0 Then
- ResetForm
- rc = VmxClose(DatasetRefNum)
- If rc <> VIS_OK Then
- TellUser (CLOSE_ERROR)
- ExitProgram 'Panic exit
- End If
- DatasetRefNum = 0 'In case the user cancels out...
- End If
- 'Announce the hard-wired open, ask for READ_ONLY or READ_WRITE:
- MBType = MB_ICONINFORMATION + MB_YESNOCANCEL
- Msg = "This sample/demonstration program is " & Chr$(34) & "hardwired" & Chr$(34) & " to work only with one specific dataset; "
- Msg = Msg & "it expects to find the " & Chr$(34) & "VBPROD" & Chr$(34) & " dataset (i.e., the three files VBPROD.ISD, "
- Msg = Msg & "VBPROD.ISM, and VBPROD.ISF, plus the optional schema file VBPROD.ISS) in "
- Msg = Msg & "the C:\ directory." & CRLFDelim & CRLFDelim
- Msg = Msg & "Note that the " & Chr$(34) & "real" & Chr$(34)
- Msg = Msg & " version of VB/ISAM Data Editor can open any VB/ISAM dataset with up to 99 fields in its record format."
- Msg = Msg & CRLFDelim & CRLFDelim
- Msg = Msg & "VBPROD is a summary of the VB add-on product listings in the Winter/Spring 1994 "
- Msg = Msg & Chr$(34) & "Component Objects and Companion Products for Visual Basic
- Programming System for Windows[TM]" & Chr$(34)
- Msg = Msg & " catalog, published by Fawcette Technical Publications for Microsoft Corporation. "
- Msg = Msg & "(Some fields, including company phone numbers, have been left "
- Msg = Msg & "blank for you to fill in.)" & CRLFDelim & CRLFDelim
- Msg = Msg & "The author of this program takes responsibility for all errors and omissions, "
- Msg = Msg & "and for the content of the " & Chr$(34) & "description" & Chr$(34) & " fields. "
- Msg = Msg & "All product names may be assumed to be trademarks or registered trademarks. "
- Msg = Msg & "All trademarks and copyrights are the properties of their respective owners."
- Msg = Msg & CRLFDelim & CRLFDelim
- Msg = Msg & "Do you want read-write access? (NO --> read-only)"
- rc = MsgBox(Msg, MBType, MBTitle)
- Select Case rc
- Case IDYES
- DatasetAccessMode = READ_WRITE
- Case IDNO
- DatasetAccessMode = READ_ONLY
- Case Else 'User clicked CANCEL
- Exit Sub
- End Select
- 'Open the dataset:
- rc = VmxOpen("c:\vbprod", DatasetRefNum) 'DEMO VERSION OF DLL (no access-mode choice; always exclusive read-write)
- If rc <> VIS_OK Then
- If rc = VIS_ACCESS_DENIED Then
- TellUser (ACCESS_DENIED)
- Else
- TellUser (OPEN_ERROR)
- End If
- Exit Sub
- End If
- 'Get dataset info (especially the StandardFormat string, which gives the record format):
- rc = VMXInfo(DatasetRefNum, DatasetInfo)
- If rc <> VIS_OK Then
- TellUser (INFO_ERROR)
- ExitProgram 'Panic exit
- End If
- pnlDatasetName.Caption = "Dataset name: C:\VBPROD"
- 'Hard-wire the FieldType array:
- NumberOfFields = 10
- FieldType(0) = "P$*50" '(primary key) Product name
- FieldType(1) = "$" 'Description
- FieldType(2) = "X45$" 'Product category
- FieldType(3) = "X$*3" 'File type
- FieldType(4) = "@" 'Base price
- FieldType(5) = "$" 'Pricing notes
- FieldType(6) = "X$*3" 'Catalog page
- FieldType(7) = "X35$" 'Company name
- FieldType(8) = "$" 'Phone
- FieldType(9) = "$" 'Fax
- FieldType(10) = "$" 'Comments
- EnableControls
- 'See if the dataset is accompanied by a .ISS ("Schema") file, containing field names:
- SchemaFileName = "c:\vbprod.iss"
- SchemaFileNum = FreeFile
- On Error GoTo CannotCreateSchemaFile
- Open SchemaFileName For Binary As #SchemaFileNum
- On Error GoTo 0
- SchemaFileAccessibleFlag = True
- 'Get schema:
- If LOF(SchemaFileNum) = 0 Then 'If we just created an empty schema file, we'll have to initialize it:
- InitSchema 'See this sub for schema-file format info.
- Else
- 'Read schema file:
- SchemaFileContents = Input$(LOF(SchemaFileNum), #SchemaFileNum)
- 'Break contents of .ISS file into comment section and schema section:
- SchemaCommentHeader = DS_GetField(SchemaFileContents, "[BEGIN SCHEMA]", 1)
- Schema = DS_GetField(SchemaFileContents, "[BEGIN SCHEMA]", 2)
- 'Strip off the CRLF (perhaps preceded by improper spaces) at the end of the "[BEGIN SCHEMA]" line:
- Schema = DS_RemoveField(Schema, CRLFDelim, 1)
- End If
- Close #SchemaFileNum
- 'Use the information in the schema to set up the display:
- ConfigureDisplay
- 'Done.
- Exit Sub
- CannotCreateSchemaFile:
- TellUser (CANT_ACCESS_SCHEMA_FILE)
- SchemaFileAccessibleFlag = False
- InitSchema
- ConfigureDisplay
- cmdRenameFields.Enabled = False
- cmdRenameFields.Picture = imgDRenameFields.Picture
- Resume ExitThisSubroutine
- ExitThisSubroutine:
- On Error GoTo 0
- Exit Sub
- End Sub
- Sub cmdRenameFields_Click ()
- Dim L, T As Integer
- Dim I As Integer
- txtFind.Text = ""
- 'Initialize frmRenameFields to display primary key:
- SchemaLine = DS_GetField(Schema, CRLFDelim, 1)
- ThisType = DS_GetField(SchemaLine, BarDelim, 2)
- frmRenameFields!lblFieldNum.Caption = "000 [" & ThisType & "]"
- frmRenameFields!txtFieldName.Text = DS_GetField(SchemaLine, BarDelim, 3)
- 'Center frmRenameFields form over frmMainForm:
- T = Me.Top + (Me.Height / 2) - (frmRenameFields.Height / 2)
- L = Me.Left + (Me.Width / 2) - (frmRenameFields.Width / 2)
- frmRenameFields.Move L, T
- FieldNum = 0 'for spin button display
- 'Initialize change-flag and go:
- SchemaDirtyFlag = False
- frmRenameFields.Show MODAL
- 'Have returned from frmRenameFields; if schema has changed, update .ISS file and change display:
- If SchemaDirtyFlag = True Then
- SchemaDirtyFlag = False
- SchemaFileNum = FreeFile
- On Error GoTo CannotOpenSchemaFile
- Open SchemaFileName For Binary Access Read Write As #SchemaFileNum 'test to see if openable...
- Close SchemaFileNum
- Kill SchemaFileName 'Destroy old file, in case new version is shorter.
- SchemaFileNum = FreeFile
- Open SchemaFileName For Binary Access Read Write As #SchemaFileNum
- On Error GoTo 0
- 'Write schema file:
- SchemaFileContents = SchemaCommentHeader & CRLFDelim & "[BEGIN SCHEMA]" & CRLFDelim & Schema
- Put #SchemaFileNum, , SchemaFileContents
- Close #SchemaFileNum
- 'Re-label fields in the display:
- For I = 0 To NumberOfFields
- SchemaLine = DS_GetField(Schema, CRLFDelim, I + 1)
- lblFieldName(I).Caption = DS_GetField(SchemaLine, BarDelim, 1) & " " & DS_GetField(SchemaLine, BarDelim, 3)
- Next I
- End If
- Exit Sub
- CannotOpenSchemaFile:
- TellUser (CANT_ACCESS_SCHEMA_FILE)
- SchemaFileAccessibleFlag = False
- cmdRenameFields.Enabled = False
- InitSchema
- 'Re-label fields in the display to correspond to the default schema built in InitSchema:
- For I = 0 To NumberOfFields
- SchemaLine = DS_GetField(Schema, CRLFDelim, I + 1)
- lblFieldName(I).Caption = DS_GetField(SchemaLine, BarDelim, 1) & " " & DS_GetField(SchemaLine, BarDelim, 3)
- Next I
- Resume QuitThisSubroutine
- QuitThisSubroutine:
- On Error GoTo 0
- Exit Sub
- End Sub
- Sub cmdUpdateRec_Click ()
- txtFind.Text = ""
- If ChangeAlertFlag = False Then
- TellUser (NOTHING_TO_UPDATE)
- Exit Sub
- End If
- DisplayedPrimaryKey = US_Trim((txtFieldVal(0).Text))
- If DisplayedPrimaryKey <> PrimaryKey Then
- TellUser (SHOULD_ADD_NOT_UPDATE)
- ElseIf PrimaryKey = "" Then
- TellUser (NULL_PRIMARY_KEY)
- Else
- AssembleRecord
- rc = VmxPut(DatasetRefNum, PrimaryKey, RecordBuffer, REPLACE_ONLY)
- If rc <> VIS_OK Then
- TellUser (PUTERROR)
- ExitProgram 'Panic exit
- Else 'VIS_OK
- FlashDisplay
- ChangeAlertFlag = False
- End If
- End If
- End Sub
- Sub cmdVCRFirst_Click ()
- Dim EmptyFlag As Integer
- txtFind.Text = ""
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- EmptyFlag = False
- rc = VmxBOF(DatasetRefNum, CurrentIndex) 'VmxBOF sets an index pointer to just BEFORE the first entry (if any) in that index.
- If rc <> VIS_OK Then
- TellUser (BOFERROR)
- ExitProgram 'Panic exit
- End If
- rc = VmxGet(DatasetRefNum, CurrentIndex, XNEXT, "", Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_OK Then
- DisplayCurrentRecord
- ElseIf rc = VIS_NOT_FOUND Then
- TellUser (INDEX_IS_EMPTY)
- EmptyFlag = True
- Else
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- cmdVCRFirst.Enabled = False
- cmdVCRFirst.Picture = imgDVCRFirst.Picture
- cmdVCRLeft.Enabled = False
- cmdVCRLeft.Picture = imgDVCRLeft.Picture
- If EmptyFlag = True Then
- cmdVCRLast.Enabled = False
- cmdVCRLast.Picture = imgDVCRLast.Picture
- cmdVCRRight.Enabled = False
- cmdVCRRight.Picture = imgDVCRRight.Picture
- Else
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRRight.SetFocus
- End If
- End Sub
- Sub cmdVCRLast_Click ()
- Dim EmptyFlag As Integer
- txtFind.Text = ""
- txtFind.Text = ""
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- EmptyFlag = False
- rc = VmxEOF(DatasetRefNum, CurrentIndex)
- If rc <> VIS_OK Then
- TellUser (EOFERROR)
- ExitProgram 'Panic exit
- End If
- rc = VmxGet(DatasetRefNum, CurrentIndex, XPREVIOUS, "", Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_OK Then
- DisplayCurrentRecord
- ElseIf rc = VIS_NOT_FOUND Then
- TellUser (INDEX_IS_EMPTY)
- EmptyFlag = True
- Else
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- cmdVCRLast.Enabled = False
- cmdVCRLast.Picture = imgDVCRLast.Picture
- cmdVCRRight.Enabled = False
- cmdVCRRight.Picture = imgDVCRRight.Picture
- If EmptyFlag = True Then
- cmdVCRFirst.Enabled = False
- cmdVCRFirst.Picture = imgDVCRFirst.Picture
- cmdVCRLeft.Enabled = False
- cmdVCRLeft.Picture = imgDVCRLeft.Picture
- Else
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- cmdVCRLeft.SetFocus
- End If
-
- End Sub
- Sub cmdVCRLeft_Click ()
- txtFind.Text = ""
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- rc = VmxGet(DatasetRefNum, CurrentIndex, XPREVIOUS, "", Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_OK Then
- DisplayCurrentRecord
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- ElseIf rc = VIS_NOT_FOUND Then 'We're at BOF in this index.
- cmdVCRFirst_Click 'A bit redundant, but handy.
- Else
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- End Sub
- Sub cmdVCRRight_Click ()
- txtFind.Text = ""
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- rc = VmxGet(DatasetRefNum, CurrentIndex, XNEXT, "", Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_OK Then
- DisplayCurrentRecord
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- ElseIf rc = VIS_NOT_FOUND Then 'We're at EOF in this index.
- cmdVCRLast_Click 'A bit redundant, but handy.
- Else
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- End Sub
- Sub cmdVCRSeek_Click ()
- Dim SearchArgument As String
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Exit Sub
- End If
- End If
- SearchArgument = US_Trim((txtFind.Text))
- If SearchArgument = "" Then
- TellUser (NO_SEARCH_TEXT)
- Else
- If CurrentIndex = 6 Then SearchArgument = Format$(Val(SearchArgument), "000") 'Page number
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- rc = VmxGet(DatasetRefNum, CurrentIndex, XLOOKUP, SearchArgument, Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_OK Then 'exact match!
- DisplayCurrentRecord
- ElseIf rc = VIS_NOT_FOUND Then 'No exact match; advance to the next entry:
- rc = VmxGet(DatasetRefNum, CurrentIndex, XNEXT, "", Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_OK Then
- DisplayCurrentRecord
- ElseIf rc = VIS_NOT_FOUND Then 'at EOF
- cmdVCRLast_Click
- Else 'error
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- Else 'error
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- End If
- End Sub
- Sub ConfigureDisplay ()
- Dim I As Integer
- Dim FNum As String
- Dim FName As String
- picFieldDisplayArea.Visible = True
- 'Initialize combo box
- cboIndex.Clear
- 'Place field names into display captions:
- For I = 0 To NumberOfFields
- SchemaLine = DS_GetField(Schema, CRLFDelim, I + 1)
- FNum = DS_GetField(SchemaLine, BarDelim, 1)
- ThisType = FieldType(I) 'Don't trust the schema file; it's user-editable.
- FName = DS_GetField(SchemaLine, BarDelim, 3)
- lblFieldName(I).Caption = FNum & " " & FName
- txtFieldVal(I).TabIndex = txtFieldVal(0).TabIndex + I
- 'If this is an index field, add a line to the (sorted) combo box:
- If (I = 0) Or (Left$(ThisType, 1) = "X") Then cboIndex.AddItem FNum & " " & FName
- Next I
- 'Init index selection combo box:
- LastIndexListIndex = 0 'to avoid triggering a change event.
- cboIndex.ListIndex = 0 'Init to primary key
- txtFieldVal(0).BackColor = BLUE
- CurrentIndex = 0
- ' 'Init display with first record in primary index sequence:
- ' cmdVCRFirst_Click
- 'Init display with a special advertising plug for VB/ISAM:
- txtFind.Text = "VB/ISAM MX for Windows"
- cmdVCRSeek_Click
- End Sub
- Function DiscardChangesQuery ()
- MBType = MB_OKCANCEL + MB_ICONQUESTION + MB_DEFBUTTON2
- Msg = "OK to discard changes?" & CRLFDelim & CRLFDelim
- Msg = Msg & "(To save changes, click CANCEL, then 'Update Record' or 'Add Record' as appropriate.)"
- DiscardChangesQuery = MsgBox(Msg, MBType, MBTitle)
- End Function
- Sub DisplayCurrentRecord ()
- SuppressChangeEventFlag = True 'See txtFieldVal()_Change event procedure
- txtFieldVal(0).Text = PrimaryKey
- txtFieldVal(1) = RecordBuffer.Description
- txtFieldVal(2) = RecordBuffer.ProductCategory
- txtFieldVal(3) = RecordBuffer.FileType
- txtFieldVal(4) = Format$(RecordBuffer.BasePrice, "Currency")
- txtFieldVal(5) = RecordBuffer.PricingNotes
- txtFieldVal(6) = Format$(Val(RecordBuffer.CatalogPage), "0")
- txtFieldVal(7) = RecordBuffer.CompanyName
- txtFieldVal(8) = RecordBuffer.Phone
- txtFieldVal(9) = RecordBuffer.Fax
- txtFieldVal(10) = RecordBuffer.Comments
- SuppressChangeEventFlag = False 'see above
- ChangeAlertFlag = False 'init
- ClearOrRestoreToggle = 0 'For clear/restore button
- End Sub
- Sub EnableControls ()
- cmdInfo.Enabled = True
- cmdInfo.Picture = imgInfo.Picture
- cmdExport.Enabled = True
- cmdExport.Picture = imgExport.Picture
- cmdVCRFirst.Enabled = True
- cmdVCRFirst.Picture = imgVCRFirst.Picture
- cmdVCRLeft.Enabled = True
- cmdVCRLeft.Picture = imgVCRLeft.Picture
- cmdVCRRight.Enabled = True
- cmdVCRRight.Picture = imgVCRRight.Picture
- cmdVCRLast.Enabled = True
- cmdVCRLast.Picture = imgVCRLast.Picture
- cmdVCRSeek.Enabled = True
- cmdVCRSeek.Picture = imgVCRSeek.Picture
- txtFind.Enabled = True
- If DatasetAccessMode = READ_WRITE Then
- cmdClearDisplay.Enabled = True
- cmdClearDisplay.Picture = imgClearDisplay.Picture
- cmdAddRec.Enabled = True
- cmdAddRec.Picture = imgAddRec.Picture
- cmdDeleteRec.Enabled = True
- cmdDeleteRec.Picture = imgDeleteRec.Picture
- cmdUpdateRec.Enabled = True
- cmdUpdateRec.Picture = imgUpdateRec.Picture
- cmdRenameFields.Enabled = True
- cmdRenameFields.Picture = imgRenameFields.Picture
- Else
- cmdClearDisplay.Enabled = False
- cmdClearDisplay.Picture = imgDClearDisplay.Picture
- cmdAddRec.Enabled = False
- cmdAddRec.Picture = imgDAddRec.Picture
- cmdDeleteRec.Enabled = False
- cmdDeleteRec.Picture = imgDDeleteRec.Picture
- cmdUpdateRec.Enabled = False
- cmdUpdateRec.Picture = imgDUpdateRec.Picture
- cmdRenameFields.Enabled = False
- cmdRenameFields.Picture = imgDRenameFields.Picture
- End If
- End Sub
- Sub FlashDisplay ()
- picFieldDisplayArea.BackColor = GREEN
- tmrTimer1.Enabled = True 'When the timer goes off, we'll restore the light-gray color.
- End Sub
- Sub Form_Load ()
- Dim L, T As Integer
- Dim I As Integer
- rc = FP_Password("Use your real password in place of this string.")
- '**************************************************************
- '*
- '* YOU MAY NOT DISTRIBUTE SOURCE CODE THAT INCLUDES YOUR
- '* FIELDPACK PASSWORD. THE CONFIDENTIALITY OF FIELDPACK
- '* PASSWORDS IS ABSOLUTELY CRITICAL, AND SOFTWARE SOURCE
- '* WILL PROSECUTE ANYONE WHO BREACHES THIS PROVISION OF
- '* THE FIELDPACK SOFTWARE LICENSE. THE FIELDPACK SOFTWARE
- '* LICENSE IS CONTAINED IN THE FIELDPACK USER'S MANUAL,
- '* FLDPAK12.WRI.
- '*
- '**************************************************************
- 'Init:
- DatasetRefNum = 0
- ChangeAlertFlag = False
- BarDelim = "|"
- CRLFDelim = Chr$(13) & Chr$(10) 'CRLF
- MBTitle = "VB/ISAM Sample Program SAM4"
- 'Load subordinate forms so their controls are available (but the forms are hidden).
- frmRenameFields.Hide
- frmInfo.Hide
- frmExport.Hide
- frmHelp.Hide
- 'Center this form on the screen:
- T = (Screen.Height / 2) - (Me.Height / 2)
- L = (Screen.Width / 2) - (Me.Width / 2)
- Me.Move L, T
- End Sub
- Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
- If UnloadMode = 0 Then 'User chose "Close" from the control-box menu
- If ChangeAlertFlag = True Then
- rc = DiscardChangesQuery()
- If rc = IDOK Then
- ChangeAlertFlag = False
- Else
- Cancel = True 'Stop the unloading process
- Exit Sub
- End If
- End If
- End If
- ExitProgram
- End Sub
- Sub FormatDatasetName ()
- 'Surprise! This procedure isn't used at all in this program.
- 'I left it in (it's from VB/ISAM Data Editor) just
- 'to show off a cute trick you can do with FieldPack.
- 'This is how VB/ISAM Data Editor modifies long pathnames
- 'for display: e.g., C:\ABCDEFGH\IJKLMNOP\...\XYZ
- ' Dim WidthLimit As Integer
- ' WidthLimit = Me.TextWidth(String$(28, "W")) 'form font is same as pnlDatasetName font
- '(The "28" is by experimentation.)
- ' DatasetName = US_Reverse(Left$(cdbOpenADataset.Filename, Len(cdbOpenADataset.Filename) - 4))
- ' If Me.TextWidth(DatasetName) > WidthLimit Then
- ' DatasetName = DS_PutField(DatasetName, "\", 2, "...")
- ' Do Until Me.TextWidth(DatasetName) <= WidthLimit
- ' DatasetName = DS_RemoveField(DatasetName, "\", 3)
- ' Loop
- ' End If
- ' DatasetName = US_Reverse(DatasetName)
- End Sub
- Sub InitSchema ()
- 'This subroutine builds a default schema, and writes it out to a schema file (.ISS).
- 'File format is:
- 'First line of file: [BEGIN COMMENTS]
- 'Zero to ?? lines: free-form comments
- 'Line ???: [BEGIN SCHEMA]
- 'Then:
- 'One variable-length line (terminated by CRLF, for friendliness for other software) for each
- 'field in the corresponding VB/ISAM dataset. (The first line represents the primary key.)
- 'Each line contains seven variable-length subfields, delimited by the "|" character
- '(so there are six delimiters). Subfields 3 through 7 can be empty.
- 'Subfield 1: 3-char field number -- 000, 001, etc. (000 for the primary key.)
- 'Subfield 2: field type -- taken from the dataset's standard record format string.
- 'Subfield 3: field name
- 'Subfield 4: display width (suggested use: for printed reports using monospaced type fonts)
- 'Subfield 5: display justification -- L, C, or R (to go along with the previous subfield)
- 'Subfield 6: reserved for Software Source
- 'Subfield 7: user-defined. Note that you can install a lower level of delimiter (perhaps a comma)
- 'to create sub-sub-fields here if you wish. Possibilities include display FontName, FontBold, etc.
- 'Note that you can also have user-defined subfields beyond the 7th, perhaps for comments.
- Dim I As Integer
- TellUser (DEFAULT_SCHEMA)
- SchemaCommentHeader = "[BEGIN COMMENTS]" & CRLFDelim 'Note, one blank comment line.
- Schema = "000|P$*" & Format$(DatasetInfo.MaxPrimaryKeyLen, "0") & "|F000||||" & CRLFDelim
- For I = 1 To NumberOfFields
- Schema = Schema & Format$(I, "000") & "|" & FieldType(I) & "|F" & Format$(I, "000") & "||||" & CRLFDelim
- Next I
- If SchemaFileAccessibleFlag = True Then 'Don't try to write default schema file if we couldn't create it.
- 'Write schema file:
- SchemaFileContents = SchemaCommentHeader & CRLFDelim & "[BEGIN SCHEMA]" & CRLFDelim & Schema
- Put #SchemaFileNum, , SchemaFileContents
- Close #SchemaFileNum
- End If
- End Sub
- Sub lblFieldName_Click (Index As Integer)
- Dim I As Integer
- For I = 0 To cboIndex.ListCount - 1
- If Val(Left$(cboIndex.List(I), 3)) = Index Then
- cboIndex.ListIndex = I
- Exit Sub
- End If
- Next I
- End Sub
- Sub RefindRecord ()
- 'This routine is called from cboIndex_Click.
- 'The idea is to establish the pointer in the new index at the position of the currently-
- 'displayed record. VmxGet always moves the pointer in the specified index.
- Dim TargetIndexValue As String
- Dim EncounteredIndexEntry As String
- If CurrentIndex = 0 Then 'i.e., we're in the primary index now:
- If PrimaryKey <> "" Then 'i.e., we haven't just deleted this record; seek to the current primary key:
- rc = VmxGet(DatasetRefNum, 0, XLOOKUP + XNO_DATA, PrimaryKey, Throwaway, PrimaryKey, Throwaway)
- If rc <> VIS_OK Then 'It better be there!
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- Else 'PrimaryKey =0; i.e., we just deleted this record. Display first record in index 0.
- cmdVCRFirst_Click
- End If
- Else 'The new index is a secondary index. We need the current rec's index-field:
- Select Case CurrentIndex
- Case 2
- TargetIndexValue = RecordBuffer.ProductCategory
- Case 3
- TargetIndexValue = RecordBuffer.FileType
- Case 6
- TargetIndexValue = RecordBuffer.CatalogPage
- Case 7
- TargetIndexValue = RecordBuffer.CompanyName
- Case Else
- TellUser (99) 'Programming error.
- ExitProgram 'Panic exit
- End Select
- If TargetIndexValue = "" Then
- cmdVCRFirst_Click
- ElseIf PrimaryKey <> "" Then 'i.e., we haven't just deleted this record.
- 'First, reposition to the first of several possible duplicates in the secondary index:
- SavedPrimaryKey = PrimaryKey 'Now, SavedPrimaryKey is the original record's primary key.
- rc = VmxGet(DatasetRefNum, CurrentIndex, XLOOKUP + XNO_DATA, TargetIndexValue, Throwaway, PrimaryKey, Throwaway)
- If rc <> VIS_OK Then 'It better be there!
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- 'Second, loop (if necessary) to reposition to the SPECIFIC entry in this index;
- 'Note that we don't have to re-retrieve the dataset record because it's already here.
- 'EXPLANATION: VB/ISAM maintains a "primary" index of unique "primary keys," plus
- 'up to 80 "secondary indexes," whose entries ("secondary keys") need not be unique.
- 'Within each secondary index, if there are "duplicate keys," VB/ISAM maintains those
- 'entries in ascending order by primary key. For example, in an employee file with
- 'primary key of Social Security Number (unique), all twenty-seven employees named
- '"Smith" will have adjacent entries in the last-name index, but those entries will
- 'appear in ascending sequence by the corresponding Social Security Numbers.
- Do Until PrimaryKey = SavedPrimaryKey
- rc = VmxGet(DatasetRefNum, CurrentIndex, XNEXT + XEQ + XNO_DATA, TargetIndexValue, Throwaway, PrimaryKey, Throwaway)
- If rc <> VIS_OK Then
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- Loop
- Else 'PrimaryKey is 0; i.e., we just deleted this record.
- 'The design decision is to display the record for the NEXT entry in the new index.
- 'First, reposition to the first of several possible duplicates in the secondary index:
- '(Note that cmdDeleteRec saved the original Primary Key in "SavedPrimaryKey")
- rc = VmxGet(DatasetRefNum, CurrentIndex, XLOOKUP, TargetIndexValue, Throwaway, PrimaryKey, RecordBuffer)
- If rc = VIS_NOT_FOUND Then 'i.e., we're just deleted the ONLY such entry (no duplicates)
- cmdVCRRight_Click
- ElseIf rc = VIS_OK Then 'i.e., there are duplicates; scan forward to just beyond where the entry used to be:
- Do Until PrimaryKey > SavedPrimaryKey Or EncounteredIndexEntry > TargetIndexValue Or rc = VIS_NOT_FOUND
- rc = VmxGet(DatasetRefNum, CurrentIndex, XNEXT, "", EncounteredIndexEntry, PrimaryKey, RecordBuffer)
- If rc <> VIS_OK And rc <> VIS_NOT_FOUND Then
- TellUser (GETERROR)
- ExitProgram 'Panic exit
- End If
- Loop
- 'Now, we're either within the duplicates but just beyond the original primarykey,
- 'or we're at the (first of the) next (set of) secondary index values,
- 'or we're at EOF.
- If rc = VIS_OK Then
- DisplayCurrentRecord
- Else 'at EOF in this index
- cmdVCRLast_Click
- End If
- End If
- End If
- End If
- End Sub
- Sub ResetForm ()
- picFieldDisplayArea.Visible = False
- ChangeAlertFlag = False
- pnlDatasetName.Caption = "Dataset name: [click Open]"
- cboIndex.Clear
- txtFieldVal(CurrentIndex).BackColor = WHITE
- cmdInfo.Enabled = False
- cmdInfo.Picture = imgDInfo.Picture
- cmdRenameFields.Enabled = False
- cmdRenameFields.Picture = imgDRenameFields.Picture
- cmdExport.Enabled = False
- cmdExport.Picture = imgDExport.Picture
- cmdVCRFirst.Enabled = False
- cmdVCRFirst.Picture = imgDVCRFirst.Picture
- cmdVCRLast.Enabled = False
- cmdVCRLast.Picture = imgDVCRLast.Picture
- cmdVCRLeft.Enabled = False
- cmdVCRLeft.Picture = imgDVCRLeft.Picture
- cmdVCRRight.Enabled = False
- cmdVCRRight.Picture = imgDVCRRight.Picture
- cmdVCRSeek.Enabled = False
- cmdVCRSeek.Picture = imgDVCRSeek.Picture
- cmdClearDisplay.Enabled = False
- cmdClearDisplay.Picture = imgDClearDisplay.Picture
- cmdAddRec.Enabled = False
- cmdAddRec.Picture = imgDAddRec.Picture
- cmdDeleteRec.Enabled = False
- cmdDeleteRec.Picture = imgDDeleteRec.Picture
- cmdUpdateRec.Enabled = False
- cmdUpdateRec.Picture = imgDUpdateRec.Picture
- End Sub
- Sub tmrTimer1_Timer ()
- picFieldDisplayArea.BackColor = LIGHT_GREY
- tmrTimer1.Enabled = False
- End Sub
- Sub txtFieldVal_Change (Index As Integer)
- If SuppressChangeEventFlag = False Then 'i.e., if this event was triggered by a USER change:
- If DatasetAccessMode = READ_ONLY Then
- txtFieldVal(Index).Text = txtFieldVal(Index).Tag 'Restore original contents; see GotFocus event.
- Beep
- Else 'i.e., user change to a field with dataset open in read-write mode:
- ChangeAlertFlag = True
- End If
- End If
- End Sub
- Sub txtFieldVal_GotFocus (Index As Integer)
- 'Prepare for possible restoration of original value if user
- 'tries to change contents when in read-only mode:
- If DatasetAccessMode = READ_ONLY Then
- txtFieldVal(Index).Tag = txtFieldVal(Index).Text 'Save original contents
- End If
- End Sub
- Sub txtFieldVal_LostFocus (I As Integer)
- Dim TempInteger As Integer
- Dim TempLong As Long
- Dim TempSingle As Single
- Dim TempDouble As Double
- Dim TempCurrency As Currency
- Dim TempString As String
- 'Reformat numeric fields, in case the user changed them:
- Select Case FieldType(I)
- Case "%"
- TempInteger = Val(US_StripOut((txtFieldVal(I).Text), ","))
- txtFieldVal(I).Text = Format$(TempInteger, "#,##0")
- Case "&"
- TempLong = Val(US_StripOut((txtFieldVal(I).Text), ","))
- txtFieldVal(I).Text = Format$(TempLong, "#,##0")
- Case "!"
- TempSingle = Val(US_StripOut((txtFieldVal(I).Text), ","))
- txtFieldVal(I).Text = Format$(TempSingle, "Scientific")
- Case "#"
- TempDouble = Val(US_StripOut((txtFieldVal(I).Text), ","))
- txtFieldVal(I).Text = Format$(TempDouble, "Scientific")
- Case "@"
- TempCurrency = Val(US_StripOut((txtFieldVal(I).Text), ",$"))
- txtFieldVal(I).Text = Format$(TempCurrency, "Currency")
- Case Else 'either $ or $*nnn
- End Select
- End Sub
-